package com.algorithm.threehundred2fourhundred;

/**
 * @author tuzhijin
 */
public class ReverseString_344 {

    public static void main(String[] args) {
        char[] chars = {'h', 'e', 'l', 'l', 'o'};
        System.out.println(reverseString(chars));
    }

    public static char[] reverseString(char[] s) {
        int left = 0, right = s.length - 1;
        // 双指针法，首尾交换
        while (left < right) {
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            right--;
            left++;
        }
        return s;
    }
}
